﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ISchool
{
    class IPanel_State:System.Windows.Forms.Panel
    {
        //判断窗体是否可以开始移动
        private bool mMouseMove = false;
        //活动变量，获取鼠标即时位置，用于窗体移动
        private int _x = 0;
        private int _y = 0;

        public IPanel_State()
        { 

        }
        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Left)
            {
                mMouseMove = true;
                _x = MousePosition.X;
                _y = MousePosition.Y;
            }
            
        }
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (AndPanel != null)
            {
                AndPanel.Visible = false;
            }
            if (mMouseMove == true)
            {
                _x = MousePosition.X - _x;
                _y = MousePosition.Y - _y;
                int i = this.Parent.Location.X + _x;
                int j = this.Parent.Location.Y + _y;
                if (i <= 0) { i = 0; }
                if (j <= 0) { j = 0; }
                if (i + this.Parent.Width >= 800) { i =800 - this.Parent.Width; }
                if (j + this.Parent.Height >= 530) { j = 530 - this.Parent.Height; }
                this.Parent.Location = new System.Drawing.Point(i, j);
                _x = MousePosition.X;
                _y = MousePosition.Y;
            }
        }
        protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
        {
            mMouseMove = false;
            base.OnMouseUp(e);
        }
        private System.Windows.Forms.Panel AndPanel;
        public void setVisiblePanel(System.Windows.Forms.Panel t)
        {
            AndPanel = t;
        }
    }
}
